package com.auxgroup.hr.front.site.co.personnel;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.vo.person.EmplPhotoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.EmplPhotoPrimary;
import com.auxgroup.hr.front.dao.domain.PsEmplPhoto;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.personnal.EmplPhotoService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.vo.person.EmplPhotoVO;

/**
 * 人员照片信息
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/emplPhoto")
public class EmplPhotoCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(EmplPhotoCO.class);

	@Autowired
	public EmplPhotoService emplPhotoService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 根据人员id和 图片类型查看人员照片
	 * @param emplid
	 * @param photoSizename
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String emplid,String photoSizename) {
		logger.info("getEmplPhoto param= {}", emplid);
		if(photoSizename == "" || null == photoSizename) photoSizename = "PAGE";
		EmplPhotoPrimary emplPhotoPrimary = new EmplPhotoPrimary(emplid,photoSizename);
		PsEmplPhoto emplPhoto = emplPhotoService.getEmplPhoto(emplPhotoPrimary);
		String jpgUrl = emplPhotoService.buildEmplPhoto(emplPhoto);
		EmplPhotoVO photo = objectMapper.map(emplPhoto, EmplPhotoVO.class);
		photo.setPhotoUrl(jpgUrl.toString());
		return buildRespone(photo);
	}
	
}
